<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		<script type="text/javascript">
			let arr =  []
			for(let i =0;i<=100;i++){
				arr.push(i)
			}
			console.log(arr);
			/**
			* 二分查找，是在一个有序的序列里查找某一个值，
			*	递归二分查找
			*	设定区间,low和high
			*	找出口： 找到target，返回target；
			*	否则寻找，当前次序没有找到，把区间缩小后递归
			 */
			function BinarySearch(arr,target,low=0,high=arr.length-1){
				const n = Math.floor((low+high)/2) //中间值
				const cur = arr[n]
				if(cur==target){
					return `找到了${target},在第${n+1}个位置`
				}else if(cur>target){
					return BinarySearch(arr,target,low,n-1)
				}else if(cur<target){
					return BinarySearch(arr,target,n+1,high)
				}
				return -1
			}
			console.log(BinarySearch(arr,50))

		</script>
	</body>
</html>
